package com.game.server.message.proto.execute;

import com.comm.ISession;

import com.game.majiang.config.DataManager;
import com.game.majiang.config.LogManager;
import com.game.majiang.logic.LogicClient;
import com.game.majiang.logic.LogicServer;
import com.game.server.db.dao.XyClubMemberInfoDao;
import com.game.server.db.entity.XyClubInfo;
import com.game.server.db.entity.XyClubMemberInfo;
import com.game.server.message.proto.in.AbstractXYclubserchReq;
import com.game.server.message.proto.out.XYclubinfoStruct;
import com.game.server.message.proto.out.XYclubserchRsp;

public class XYclubserchReq extends AbstractXYclubserchReq {

    @Override
    public void Execute(ISession session) {
        LogicClient client = (LogicClient) LogicServer.getInstance().getClient(session.getId());
        if (client != null&&client.checkClick(msgcode)) {
            XYclubserchRsp rsp = new XYclubserchRsp();
            rsp.setIsok(1);
            rsp.setSearchid(this.id);
            XyClubInfo clubInfo = DataManager.getInstance().getMapClub().get(this.id);
            rsp.setType(1);
            if (clubInfo==null){
                int cid = XyClubMemberInfoDao.findPartnerIdBackCid(this.id);
                if (cid!=0){
                    rsp.setType(2);
                    clubInfo = DataManager.getInstance().getMapClub().get(cid);
                }
            }
            if (clubInfo!=null){
                rsp.setIsok(2);
                XyClubMemberInfo player = clubInfo.getPlayer().get(client.getUserId());
                if (player==null){
                    rsp.setIsok(0);
                    XYclubinfoStruct xYclubinfoStruct = new XYclubinfoStruct();
                    xYclubinfoStruct.setId(clubInfo.getId());
                    xYclubinfoStruct.setName(clubInfo.getName());
                    xYclubinfoStruct.setHeadurl(clubInfo.getHeadurl());
                    xYclubinfoStruct.setContent(clubInfo.getContent());
                    xYclubinfoStruct.setCreatorid(clubInfo.getCreatorid());
                    xYclubinfoStruct.setCreatorhead(DataManager.getInstance().getMapUserData().get(clubInfo.getCreatorid()).getHead());
                    xYclubinfoStruct.setCreatorname(DataManager.getInstance().getMapUserData().get(clubInfo.getCreatorid()).getName());
                    LogManager.getInstance().Log("加入俱乐部clubInfo.getId()："+clubInfo.getId());
                    LogManager.getInstance().Log("加入俱乐部clubInfo.getName()："+clubInfo.getName());
                    LogManager.getInstance().Log("加入俱乐部clubInfo.getCreatedate()："+clubInfo.getCreatedate());
                    xYclubinfoStruct.setCreatedate(clubInfo.getCreatedate().getTime()+"");
                    rsp.setClubinfo(xYclubinfoStruct);
                }else{
                    if (player.getDel_type()==1){
                        rsp.setIsok(0);
                        XYclubinfoStruct xYclubinfoStruct = new XYclubinfoStruct();
                        xYclubinfoStruct.setId(clubInfo.getId());
                        xYclubinfoStruct.setName(clubInfo.getName());
                        xYclubinfoStruct.setHeadurl(clubInfo.getHeadurl());
                        xYclubinfoStruct.setContent(clubInfo.getContent());
                        xYclubinfoStruct.setCreatorid(clubInfo.getCreatorid());
                        xYclubinfoStruct.setCreatorhead(DataManager.getInstance().getMapUserData().get(clubInfo.getCreatorid()).getHead());
                        xYclubinfoStruct.setCreatorname(DataManager.getInstance().getMapUserData().get(clubInfo.getCreatorid()).getName());
                        xYclubinfoStruct.setCreatedate(clubInfo.getCreatedate().getTime()+"");
                        rsp.setClubinfo(xYclubinfoStruct);
                    }
                }
            }
            client.Send(rsp);
        }
    }

}
